﻿using System;
using UnityEditor;
using UnityEngine;

namespace E.Story
{
    /// <summary>
    /// 属性框实用类
    /// </summary>
    public static class InspectorUtility
    {
        /// <summary>
        /// 绘制不可修改值的输入框
        /// </summary>
        /// <param name="action">触发行为</param>
        public static void DrawDisabledField(Action action)
        {
            EditorGUI.BeginDisabledGroup(true);

            action.Invoke();

            EditorGUI.EndDisabledGroup();
        }

        /// <summary>
        /// 绘制标题
        /// </summary>
        /// <param name="label">标题文本</param>
        public static void DrawHeader(string label)
        {
            EditorGUILayout.LabelField(label, EditorStyles.boldLabel);
        }

        /// <summary>
        /// 绘制选项框
        /// </summary>
        /// <param name="message">消息</param>
        /// <param name="messageType">消息类型</param>
        /// <param name="wide">是否全宽</param>
        public static void DrawHelpBox(string message, MessageType messageType = MessageType.Info, bool wide = true)
        {

            EditorGUILayout.HelpBox(message, messageType, wide);
        }

        /// <summary>
        /// 绘制属性输入框
        /// </summary>
        /// <param name="sp">属性</param>
        public static void DrawPropertyField(this SerializedProperty sp, string label)
        {
            EditorGUILayout.PropertyField(sp, new GUIContent(label));
        }

        /// <summary>
        /// 绘制下拉菜单
        /// </summary>
        /// <param name="label">标签</param>
        /// <param name="sp">属性</param>
        /// <param name="options">选项</param>
        /// <returns>索引</returns>
        public static int DrawPopup(string label, SerializedProperty sp, string[] options)
        {
            return EditorGUILayout.Popup(label, sp.intValue, options);
        }

        /// <summary>
        /// 绘制下拉菜单
        /// </summary>
        /// <param name="label">标签</param>
        /// <param name="index">索引</param>
        /// <param name="options">选项</param>
        /// <returns>索引</returns>
        public static int DrawPopup(string label, int index, string[] options)
        {
            return EditorGUILayout.Popup(label, index, options);
        }

        /// <summary>
        /// 绘制空行
        /// </summary>
        /// <param name="amount">行高</param>
        public static void DrawSpace(int amount = 4)
        {
            EditorGUILayout.Space(amount);
        }
    }
}